<script setup lang="ts">
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';

import { preferences } from '@vben/preferences';
import { useAccessStore } from '@vben/stores';

import { Spin } from 'ant-design-vue';

const accessStore = useAccessStore();

const route = useRoute();
const router = useRouter();

onMounted(() => {
  // 从路由中获取token
  const token = route.query.token || route.params.token;
  if (token) {
    // 设置本地token
    accessStore.setAccessToken(token as string);

    // 重定向到指定页面
    const redirect =
      (route.query.redirect as string) || preferences.app.defaultHomePath;
    router.replace(redirect);
  } else {
    // token不存在，跳转到登录页
    router.replace({
      name: 'Login',
    });
  }
});
</script>

<template>
  <div class="flex h-full w-full items-center justify-center">
    <!-- 加载提示 -->
    <Spin tip="登录处理中..." />
  </div>
</template>
